package com.dhcc.DRGsHosp.web.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dayatang.utils.Page;
import org.openkoala.koala.commons.InvokeResult;
import org.openkoala.security.shiro.CurrentUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dhcc.DRGsHosp.facade.DailyRecordFacade;
import com.dhcc.DRGsHosp.facade.dto.DailyRecordDTO;
import com.dhcc.DRGsHosp.facade.dto.DepShowDTO;

@Controller("drgsHospWebController4")
@RequestMapping("/DailyRecord")
public class DailyRecordController {
		
	@Autowired
	private DailyRecordFacade dailyRecordFacade;
	
	@ResponseBody
	@RequestMapping("/add")
	public InvokeResult add(DailyRecordDTO dailyRecordDTO) {
		return dailyRecordFacade.creatDailyRecord(dailyRecordDTO);
	}
	
	@ResponseBody
	@RequestMapping("/update")
	public InvokeResult update(DailyRecordDTO dailyRecordDTO) {
		return dailyRecordFacade.updateDailyRecord(dailyRecordDTO);
	}
	
	@ResponseBody
	@RequestMapping("/pageJson")
	public Page pageJson(DailyRecordDTO dailyRecordDTO, @RequestParam int page, @RequestParam int pagesize) {
		Page<DailyRecordDTO> all = dailyRecordFacade.pageQueryDailyRecord(dailyRecordDTO, page, pagesize);
		return all;
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public InvokeResult remove(@RequestParam String drEpisodeids) {
		String[] value = drEpisodeids.split(",");
        String[] idArrs = new String[value.length];
        for (int i = 0; i < value.length; i ++) {
        					idArrs[i] = value[i];
			        				        }
        return dailyRecordFacade.removeDailyRecords(idArrs);
	}
	
	@ResponseBody
	@RequestMapping("/get/{drEpisodeid}")
	public InvokeResult get(@PathVariable String drEpisodeid) {
		return dailyRecordFacade.getDailyRecord(drEpisodeid);
	}
	
		
    @InitBinder    
    public void initBinder(WebDataBinder binder) {  
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");    
        dateFormat.setLenient(false);    
        //CustomDateEditor 可以换成自己定义的编辑器。
        //注册一个Date 类型的绑定器 。
        binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }
    
    /**
     * 
     * @methodname    :getDepShow
     * @description   : 
     * @param         :
     * @author        :fulianxia
     * @return        :
     * @date          :2015年5月8日
     */
    @ResponseBody
    @RequestMapping(value = "/getDepShow", method = RequestMethod.POST)
    public InvokeResult getDepShow(DepShowDTO depShowDto) {
    	return dailyRecordFacade.getDepShow(depShowDto);
    }
    
    /**
     *  @Discription：获取周监测数据
     *  @Author： liuhongjun
     *  @param depShowDto
     *  @return list
     *  @Date:2018年11月6日下午8:40:03
     */
    @ResponseBody
    @RequestMapping(value = "/getDepWeekData", method = RequestMethod.POST)
    public InvokeResult getDepWeekData(DepShowDTO depShowDto) {
    	return dailyRecordFacade.getDepWeekData(depShowDto);
    }
    
    /**
     * 
     * @methodname    :sendMessage
     * @description   : 
     * @param         :
     * @author        :pc
     * @return        :
     * @date          :2015年5月8日
     */
    @ResponseBody
    @RequestMapping(value = "/sendMessage", method = RequestMethod.POST)
    public InvokeResult sendMessage(DepShowDTO depShowDto) {
    	return dailyRecordFacade.sendMessage(depShowDto);
    }
    
    
    /**
     * 
     * @methodname    :getDepShow
     * @description   : 
     * @param         :
     * @author        :fulianxia
     * @return        :
     * @date          :2015年5月8日
     */
    @ResponseBody
    @RequestMapping(value = "/getDepOnlyShow", method = RequestMethod.POST)
    public InvokeResult getDepOnlyShow(DepShowDTO depShowDto) {
    	return dailyRecordFacade.getDepOnlyShow(depShowDto);
    }
    /**
     *  @Discription：获取日监测数据最大值
     *  @Author： liuhongjun
     *  @param depShowDto
     *  @return
     *  @Date:2018年5月6日上午8:36:46
     */
    @ResponseBody
    @RequestMapping(value = "/getLastestIssue", method = RequestMethod.POST)
    public InvokeResult getLastestIssue(DepShowDTO depShowDto) {
    	return dailyRecordFacade.getLastestIssue(depShowDto);
    }
    
    /**
     * 
     * @methodname    :getIsAbnormal
     * @description   : 
     * @param         :
     * @author        :fulianxia
     * @return        :
     * @date          :2015年5月12日
     */
    @ResponseBody
    @RequestMapping(value = "/getIsAbnormal", method = RequestMethod.POST)
    public InvokeResult  getIsAbnormal(DepShowDTO depShowDto){
    	return dailyRecordFacade.getIsAbnormal(depShowDto);
    }
    
    /**
     * 
     * @methodname    :getIsAbnormal
     * @description   : 
     * @param         :
     * @author        :fulianxia
     * @return        :
     * @date          :2015年5月12日
     */
    @ResponseBody
    @RequestMapping(value = "/getRole", method = RequestMethod.POST)
    public Map<String, Object>  getRole(){
    	Map<String, Object> map = new HashMap<String, Object>();
    	String roleName = CurrentUser.getRoleName();
    	String depCode = CurrentUser.getDepYb();
    	map.put("roleName", roleName);
    	map.put("depCode", depCode);
    	return map;
    }
    
    /**
     * @methodname    :saveOrUpdate
     * @description   :修改异常科室
     * @param         :
     * @author        :WangTeng
     * @return        :
     * @date          :2015年6月24日
     */
    @ResponseBody
    @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
    public InvokeResult saveOrUpdate(DepShowDTO depShowDto) {
    	return dailyRecordFacade.saveOrUpdate(depShowDto);
    }
    
    /**
     * @methodname    :saveOrUpdate
     * @description   :修改异常科室
     * @param         :
     * @author        :WangTeng
     * @return        :
     * @date          :2015年6月24日
     */
    @ResponseBody
    @RequestMapping(value = "/daysDataImport", method = RequestMethod.POST)
    public InvokeResult daysDataImport(String wsUrl,String method,String hospCode ) {
    	return dailyRecordFacade.daysDataImport(wsUrl,method,hospCode);
    }
	
    /**
     * 
     * @methodname    :getChangeDetail
     * @description   :转科病人病例明细 
     * @param         :
     * @author        :sulina
     * @return        :
     * @date          :2015年7月10日
     */
    @ResponseBody
    @RequestMapping(value = "/getChangeDetail", method = RequestMethod.POST)
    public InvokeResult getChangeDetail(DepShowDTO depShowDto) {
    	return dailyRecordFacade.getChangeDetail(depShowDto);
    }
    

    /**
     * 
     *  findDailyRecordInterFace.  
     *  @Description：监测病例日监测接口配置
     *  @Author LiuHongjun
     *  @return 
     *  @Date:2017年6月19日上午7:25:51
     */
    @ResponseBody
    @RequestMapping(value = "/findDailyRecordInterFace", method = RequestMethod.POST)
    public InvokeResult findDailyRecordInterFace() {
    	return dailyRecordFacade.findDailyRecordInterFace();
    }
    
    
	/**
	 * 
	 *  findDailyRecords.  
	 *  @Description：查询异常日监测数据
	 *  @Author LiuHongjun
	 *  @return 
	 *  @Date:2017年6月19日下午4:51:43
	 */
	@ResponseBody
	@RequestMapping("/findDailyRecords"  )  
    public List<DailyRecordDTO> findDailyRecords(DepShowDTO depShowDto){  
        return dailyRecordFacade.findDailyRecords(depShowDto);
    }
}
